package com.ctshk.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 渠道来源主数据
 */
@Getter
@AllArgsConstructor
public enum ChannelMainData {

    APP_H5(1364862906379980801L, "APP&H5", "MOBILE"),
    CHINA_TRAVEL(1364862797655232514L, "中旅网", "PC");

    private long id;
    private String msg;
    private String code;

    public static Long getIdByCode(String code) {
        ChannelMainData channelMainData = Arrays.stream(ChannelMainData.values())
                .filter(enums -> enums.getCode().equals(code)).findFirst().orElse(null);
        if (channelMainData != null) {
            return channelMainData.getId();
        }
        return null;
    }

    public static ChannelMainData getById(Long channelId) {
        ChannelMainData channelMainData = Arrays.stream(ChannelMainData.values())
                .filter(enums -> Objects.equals(enums.getId(), channelId)).findFirst().orElse(null);
        return channelMainData;
    }

    public static boolean isPcById(Long channelId) {
        return ChannelMainData.APP_H5.getId() == channelId ? true : false;
    }

    public static boolean isMobileById(Long channelId) {
        return ChannelMainData.CHINA_TRAVEL.getId() == channelId ? true : false;
    }

}
